package cn.eleven.controller;

import cn.eleven.common.Result;
import cn.eleven.entity.Staff;
import cn.eleven.service.StaffService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@CrossOrigin("*")
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @GetMapping("/all")
    public Result getAllStaff() {
        List<Staff> staffList = staffService.getAllStaff();
        return Result.success(staffList);
    }

    @GetMapping("/page")
    public Result getStaffByPage(int current, int size) {
        Page<Staff> page = new Page<>(current, size);
        IPage<Staff> staffPage = staffService.getStaffByPage(page);
        return Result.success(staffPage);
    }
}
